/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle <lylechen2014@gmial.com>
 * @since : 2014-08-20 10:04:58
 * @filename : static/mnm/src/views/singin.js
 * @version : 
 * @description : 
 */
define(function(require, exports, module){

        require("{resourceUrl}css/mnm/public.css");
        require("{resourceUrl}css/mnm/singin.css");

        var SingInView,
            $ = require('$'),
            _ = require('underscore'),
	    Backbone = require('backbone'),
            util = require('{baseSea}util/util'),
            share = require('../share'),
            lang = require('{baseSea}I18N/mnm/{locale}'),
            tpl = require('{resourceUrl}tpl/mnm/singin.tpl');
	
        SingInView = Backbone.View.extend({

		el: 'body',

		template: _.template(tpl),

		events: {
                    "tap .back"           : "goBack",
                    "tap .btn-singin"     : "handleSinginData"  
                },
                 
		initialize: function () {
                
                },
                 
		render: function (obj) {
                    if ($('#singin_box').length < 1) { 
                        $('body').append(this.template(lang));  
                    } else {
		        $('#singin_box').show();
                    }

                },
                
                goBack : function() {
		    window.location.href='#index/whole'; 
                },
 
                handleSinginData : function() {
                   if(parseInt($('.btn-singin').attr('ajax')) !== 1) {                  
                      var obj = {};
                      obj.EU = $('input[name="userName"]').val();
                      obj.PW = $('input[name="passWord"]').val();
		      if (this.singinValidata(obj)) {
			  this.ajaxSingin(obj,this);
		      }           
                   }
                },

                ajaxSingin : function() {
                       var dom = $('.btn-singin');
                           dom.attr('ajax',1);
                           share.ajaxStartA(dom);
                       var  obj = {
				 url : seajs.data.vars.apiUrl+'user_login',
				 type : 'POST',
				 data : data,
				 success : function(data) {
				     if (data.error == 0 ) {
					 window.location.href='#user_center/whole';
                                     } else {
                                         //errorshow
                                     }
                                  }, 
                         	  error : function(xhr, errorType, error) {
                                     share.error('alert','user_login http request failed!'); 
			          },
                                  complete : function(xhr,status){
                                     dom.attr('ajax',0);
				     share.ajaxEndA(dom);
                                  } 
			 };
                         $.ajax(util.ajaxControl(obj));
                },

                singinValidata : function(data) {
		     var obj = {bool:true,type:1};
		     for (var i in data) {
			 if ($.trim(data[i]) == '') {
				obj.bool = false;
			     }
			 obj.dom = $('.'+i);
			 obj.msg = lang.required; 
		         share.inputError(obj);
		     }
		     return obj.bool; 
		}




	});

	module.exports = SingInView;
})


